import sys

# from PyQt5.QtGui import QRegExpValidator
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
# from PyQt5.uic import loadUi
from timeCounter import Ui_MainWindow
from timeOver import Ui_TimeOver
from PyQt5.QtCore import pyqtSignal, Qt, QThread, QDate, QDateTime, QTime, QRegExp
from MyThread import TimeCountThread
import time


class MyMainWindow(QMainWindow, Ui_MainWindow):
	helpSignal = pyqtSignal(str)

	def __init__(self, parent=None):
		super(MyMainWindow, self).__init__(parent)
		self.setupUi(self)
		self.initUI()

	def initUI(self):
		self.startBtn1.clicked.connect(self.startCount)
		self.stopBtn1.clicked.connect(self.stopCount)
		regx = QRegExp("^[0-9]{14}$")
		validator = QRegExpValidator(regx, self.intervalTime)
		self.intervalTime.setValidator(validator)
		self.intervalTimeSecond.setValidator(validator)

	def startCount(self):
		self.startBtn1.setEnabled(False)
		self.TimeCount = TimeCountThread()
		time1 = int(self.intervalTime.text(), 10)
		time2 = int(self.intervalTimeSecond.text(), 10)
		self.TimeCount.data = time1 * 60 + time2
		self.TimeCount.updateStartTime.connect(self.startTimeDisplay)
		self.TimeCount.updateRunTime.connect(self.leftTimeDisplay)
		self.TimeCount.updateEnd.connect(self.timeOver)
		self.TimeCount.start()


	def timeOver(self):
		# QMessageBox.information(self, '框名', '内容')
		#
		label0 = QLabel("<font color=red size=72><b>" + "message" + "</b></font>")
		label0.setWindowFlags(Qt.SplashScreen)
		label0.show()



	def stopCount(self):
		self.TimeCount.data = 0
		self.startBtn1.setEnabled(True)

	def startTimeDisplay(self, data):
		self.startTime.setText(data)

	def leftTimeDisplay(self, data):
		self.remainingTime.setText(str(data))


if __name__ == "__main__":
	app = QApplication(sys.argv)
	win = MyMainWindow()
	win.show()
	sys.exit(app.exec_())
